<ul class="posts">
    {% for post in posts %}
    <li class="post">
        <div class="post-thumbnail">
            <a href="{{ url_for('.user', username=post.author.username) }}">
            {% if post.author.username == "wen" %} 
                <img class="img-rounded profile-thumbnail" src="../static/img/me.jpg" style="width:40px;height:40px;">
            {% else %}
                <img class="img-rounded profile-thumbnail" src="../static/img/other.jpg" style="width:40px;height:40px;">
            {% endif %}
            </a>
        </div>
        <div class="post-content">

            <div class="post-date">
            {% if current_user.is_authenticated %}
                {% if not current_user.staring(post)  %}
                <a href="{{ url_for('.star',id=post.id) }}#comments">
                <span class="label label-primary">添加到收藏</span>
                </a>
                {% else %}
                <a href="{{ url_for('.unstar',id=post.id) }}#comments">
                <span class="label label-default">取消收藏</span>
                </a>
                {% endif %}
            {% else %}
            <a href="{{ url_for('.star',id=post.id) }}#comments">
            <span class="label label-primary">添加到收藏</span>
            </a>
            {% endif %}

            {{ post.timestamp }}</div>
            <div class="post-author"><a href="{{ url_for('.user', username=post.author.username) }}">{{ post.author.username }}</a></div>
            <div class="post-head">
            <a href="{{ url_for('.post', id=post.id) }}"><h2>{{ post.head }} <small></a>&nbsp;&nbsp;&nbsp;阅读:{{ post.visits }}&nbsp;收藏:{{ post.stared.__len__() }}</small></h2>
            </div>
            <div class="post-body">
                {% if post.body_html %}                   
                    {{ post.body_html | safe }}
                {% else %}                    
                    {{ post.body }}
                {% endif %}
            </div>
            <div class="post-footer">
                {% if current_user == post.author %}
                <a href="{{ url_for('.edit', id=post.id) }}">
                    <span class="label label-primary">编辑</span>
                <a href="{{ url_for('.post_delete', id=post.id,) }}" class="label label-danger">
                    <span class="label label-danger">删除</span>
                    </a>
                </a>
                {% elif current_user.is_administrator() %}
                <a href="{{ url_for('.edit', id=post.id) }}">
                    <span class="label label-danger">编辑 [Admin]</span>
                </a>
                {% endif %}
                <!-- <a href="{{ url_for('.post', id=post.id) }}">
                    <span class="label label-default">查看</span>
                </a> -->                                
                <a href="{{ url_for('.post', id=post.id) }}#comments">
                    <span class="label label-primary">{{ post.comments.count() }} 评论</span>
                </a>
            </div>
        </div>
    </li>
    {% endfor %}
</ul>
